Skip to content

feat: use containerd gc for image-fetcher cleanup#8065

Open
awesomenix wants to merge 1 commit intomainfrom
image-fetcher-gc-cleanup
Open

feat: use containerd gc for image-fetcher cleanup#8065
awesomenix wants to merge 1 commit intomainfrom
image-fetcher-gc-cleanup

Conversation

@awesomenix
Copy link
Contributor

Summary

  • use containerd's native GC label filtering for the image-fetcher pull path instead of scanning all images
  • add an image-fetcher GC trigger entrypoint and invoke it once after the VHD preload batch completes
  • enable discard of unpacked pulled layers during VHD image preloading while preserving fetch-only image blobs

Validation

  • gofmt -w image-fetcher/main.go
  • cd image-fetcher && go build ./...
  • bash -n vhdbuilder/packer/install-dependencies.sh

Copilot AI review requested due to automatic review settings March 10, 2026 23:06
@awesomenix awesomenix changed the title Use containerd GC for image-fetcher cleanup feat: use containerd gc for image-fetcher cleanup Mar 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the VHD image preloading flow to rely on containerd’s native GC mechanics (via GC label filtering) rather than scanning images for cleanup, and adds an explicit GC trigger once the preload batch completes.

Changes:

  • Add an --gc mode to image-fetcher that triggers containerd GC via lease create/delete.
  • Update the image-fetcher pull path to apply containerd GC child-label filtering for layer blobs.
  • Invoke image-fetcher --gc once after all parallel image pulls complete during VHD build.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
vhdbuilder/packer/install-dependencies.sh Runs a single post-batch image-fetcher --gc after the image preload jobs finish.
image-fetcher/main.go Adds --gc entrypoint and applies WithChildLabelMap(images.ChildGCLabelsFilterLayers) for the pull/unpack path.

@@ -699,6 +699,7 @@ while IFS= read -r imageToBePulled; do
done <<< "$ContainerImages"
echo "Waiting for container image pulls to finish. PID: ${image_pids[@]}"
wait ${image_pids[@]}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait ${image_pids[@]} only returns the exit status of the last PID waited for, so failures in earlier background pulls can be missed (and with set -e the script would still proceed to run image-fetcher --gc). Consider iterating over PIDs (or looping wait -n until all jobs finish) and tracking any non-zero exit status so the build fails reliably before triggering GC.

Suggested change
wait ${image_pids[@]}
overall_status=0
for pid in "${image_pids[@]}"; do
if ! wait "$pid"; then
status=$?
echo "Container image pull job with PID $pid failed with exit code $status" >&2
overall_status=$status
fi
done
if [ "$overall_status" -ne 0 ]; then
echo "One or more container image pulls failed; skipping image-fetcher GC and exiting with code $overall_status" >&2
exit "$overall_status"
fi

Copilot uses AI. Check for mistakes.
Mark unpacked pulled layers as GC-eligible during VHD image preloading and trigger a single synchronous containerd GC after the preload batch. This avoids scanning all images per pull while preserving fetch-only image blobs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants